<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
	<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
	<title></title>
	<link rel="stylesheet" type="text/css" href="../../css/aui.css" />
	<link rel="stylesheet" type="text/css" href="../../css/font-awesome.css" />
</head>

<body>
	<div class="aui-content aui-margin-b-15">
		<ul class="aui-list aui-media-list">
			<li class="aui-list-item">
				<div class="aui-media-list-item-inner" id="user">
					<div class="aui-list-item-media">
						<img src="../../icon/icon.png" />
					</div>
					<div class="aui-list-item-inner">
						<div class="aui-list-item-text">
							<div class="aui-list-item-title" id="geroname">

							</div>
						</div>
						<div class="aui-list-item-text" id="username">

						</div>
					</div>
				</div>
			</li>
		</ul>
	</div>
	<div class="aui-content aui-margin-b-15">
		<ul class="aui-list aui-list-in">
			<!--<li class="aui-list-item" id="list-device" tapmode>
					<div class="aui-list-item-label-icon">
						<i class="fa fa-mobile"></i>
					</div>
					<div class="aui-list-item-inner">
						<div class="aui-list-item-title">
							设备绑定
						</div>
					</div>
				</li>-->

			<li class="aui-list-item" id="list-trash" tapmode>
				<div class="aui-list-item-label-icon">
					<i class="fa fa-trash"></i>
				</div>
				<div class="aui-list-item-inner">
					<div class="aui-list-item-title">
						缓存
					</div>
					<div class="aui-list-item-right" id="trash"></div>
				</div>
			</li>
			<li class="aui-list-item" id="list-refresh" tapmode>
				<div class="aui-list-item-label-icon">
					<i class="fa fa-refresh"></i>
				</div>
				<div class="aui-list-item-inner">
					更新
				</div>
			</li>
			<li class="aui-list-item">
				<div class="aui-list-item-label-icon">
					<i class="fa fa-television"></i>
				</div>
				<div class="aui-list-item-inner">
					当前版本
					<div class="aui-list-item-right" id="version"></div>
				</div>
			</li>
		</ul>
	</div>
	<!--div class="aui-content aui-margin-b-15">
			<ul class="aui-list aui-list-in">
				<li class="aui-list-item" id="list-idcard" tapmode>
					<div class="aui-list-item-label-icon">
						<i class="fa fa-android"></i>
					</div>
					<div class="aui-list-item-inner">
						<div class="aui-list-item-title">
							身份证感应识别
						</div>
					</div>
				</li>
			</ul>
		</div-->
	<div class="aui-content aui-margin-b-15">
		<ul class="aui-list aui-list-in">
			<li class="aui-list-item" id="list-signout" tapmode>
				<div class="aui-list-item-label-icon">
					<i class="fa fa-sign-out"></i>
				</div>
				<div class="aui-list-item-inner">
					退出
				</div>
			</li>
		</ul>
	</div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/util.js"></script>
<script type="text/javascript" src="../../script/doT.js"></script>
<script type="text/javascript">
	var id = null;
	apiready = function() {
		api.parseTapmode();
		var version = api.appVersion;
		$api.byId('version').innerText = version;
		//			api.showProgress({
		//			});

		console.log($api.getStorage('login'));
		console.log("88888888888" + JSON.stringify($api.getStorage('userinfo')));
		// 获取用户信息
		//			api.ajax({
		//				url : base + 'admin/auth/user/show'
		//			}, function(ret, err) {
		//				if (ret && ret.code != "-1") {
		//					id = ret.id;
		//					var template = $api.byId('listTemplate');
		//					var list_content = $api.byId('user');
		//					var pagefn = doT.template(template.text);
		//					list_content.insertAdjacentHTML('beforeend', pagefn(ret));
		//				} else {
		//					doLogin();
		//				}
		//				api.hideProgress();
		//			});
		if ($api.getStorage('login')) {
			$api.byId('geroname').innerHTML = $api.getStorage("userinfo").user.geroShortName;
			$api.byId('username').innerHTML = $api.getStorage("userinfo").user.userName;
		} else {
			doLogin();
		}
		// 获取缓存
		getCacheSize($api.byId('trash'));
		// 清空缓存
		$api.addEvt($api.byId('list-trash'), 'click', function() {
			api.clearCache(function() {
				api.toast({
					msg: '清除完成'
				});
				getCacheSize($api.byId('trash'));
			});
			//$api.clearStorage();
		});
		// 更新
		$api.addEvt($api.byId('list-refresh'), 'click', function() {
			var mam = api.require('mam');
			mam.checkUpdate(function(ret, err) {
				if (ret) {
					var result = ret.result;
					if (result.update == true && result.closed == false) {
						var str = '新版本型号:' + result.version + ';更新提示语:' + result.updateTip + ';下载地址:' + result.source + ';发布时间:' + result.time;
						api.confirm({
							title: '有新的版本,是否下载并安装 ',
							msg: str,
							buttons: ['确定', '取消']
						}, function(ret, err) {
							if (ret.buttonIndex == 1) {
								if (api.systemType == "android") {
									api.download({
										url: result.source,
										report: true
									}, function(ret, err) {
										if (ret && 0 == ret.state) { /* 下载进度 */
											api.toast({
												msg: "正在下载应用" + ret.percent + "%",
												duration: 2000
											});
										}
										if (ret && 1 == ret.state) { /* 下载完成 */
											var savePath = ret.savePath;
											api.installApp({
												appUri: savePath
											});
										}
									});
								}
								if (api.systemType == "ios") {
									api.installApp({
										appUri: result.source
									});
								}
							}
						});
					} else {
						api.alert({
							msg: "暂无更新"
						});
					}
				} else {
					api.alert({
						msg: err.msg
					});
				}
			});
		});
		// 退出
		$api.addEvt($api.byId('list-signout'), 'click', function() {
			$api.setStorage('login', false);
			api.sendEvent({
				name: 'logout',
				extra: {
					login: false
				}
			});
			api.closeWin({});
		});
		// 设备绑定
		$api.addEvt($api.byId('list-device'), 'click', function() {
			var device_token = api.getPrefs({
				sync: true,
				key: 'device_token'
			});
			console.log(device_token);
			api.ajax({
				url: base + 'admin/auth/user/save',
				method: 'post',
				data: {
					values: {
						"m": "update",
						"model.device_token": device_token,
						"model.id": id
					}
				}
			}, function(ret, err) {
				if (ret && ret.code != "-1") {
					if (ret.STATUS) {
						tips('绑定成功');
					} else {
						tips('绑定失败');
					}
				} else {
					doLogin();
				}
			});
		});
		// 身份证感应识别
		$api.addEvt($api.byId('list-idcard'), 'click', function() {
			api.confirm({
				msg: '是否下载并安装应用',
				buttons: ['确定', '取消']
			}, function(ret, err) {
				if (ret.buttonIndex == 1) {
					api.download({
						//url: base + 'upload/apk/idcard-bmp.apk',
						url:'http://jbinfo-ipp.oss-cn-hangzhou.aliyuncs.com/ipp-mod-gero/LFhTRKdef0TBR0Ri/soo/app/andriodaad494cb004c798b2a5a3b02030453d6.apk',
						report: true,
						cache: true,
						allowResume: true
					}, function(ret, err) {
						if (ret.state == 1) {
							//下载成功
							console.log(JSON.stringify(ret));
							api.installApp({
								appUri: ret.savePath
							});
						} else {}
					});
				}
			});
		});
	};
</script>

</html>
